﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Entity;
using vdos.jobseeker.Utils;
using vdos.jobseeker.Model;

namespace vdos.jobseeker.AdminCP.Company
{
    public partial class company_edit : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["USER"] == null) { Response.Redirect("/login.aspx"); }
            //else
            //{
            //    if (hash1way.CheckPermission(hash1way.GetPermission(Session["USER"].ToString()), "SYSADMIN") == false)
            //    {
            //        if (hash1way.CheckPermission(hash1way.GetPermission(Session["USER"].ToString()), "HOMEPAGE") == false)
            //        {
            //            Response.Redirect("/message_box.aspx?why=1&msg=5");
            //        }
            //    }
            //}

            if (!Page.IsPostBack)
            {
                try
                {
                    Int64 nCompanyID = ConvertUtility.ToInt64(Request.QueryString["CompanyID"]);

                    var context = new jobseekerEntities();
                    var company = context.Company.Where(t => t.CompanyID == nCompanyID).FirstOrDefault();

                    //var dt = DataHelper.SelectTable("Select * from Company where CompanyID =" + nCompanyID, false);

                    CompanyID.Value = company.CompanyID.ToString();
                    CompanyName.Value = company.CompanyName;
                    CompanyDetail.Value = company.CompanyDetails;
                    LogoFilePath.Value = company.CompanyLogo;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            update();
            Response.Redirect("/Company/company_all_published.aspx");
        }

        protected void update()
        {
            try
            {
                string sLogo = LogoFilePath.Value;
                string sCompanyName = CompanyName.Value;
                string sCompanyDetail = CompanyDetail.Value;
                Int64 nCompanyID = ConvertUtility.ToInt64(CompanyID.Value);

                var context = new jobseekerEntities();
                var company = context.Company.FirstOrDefault(t => t.CompanyID == nCompanyID);

                company.CompanyLogo = sLogo;
                company.CompanyName = sCompanyName;
                company.CompanyDetails = sCompanyDetail;

                int rs = context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
                                    
        }

        
    }
}
